import {makeAutoObservable,computed} from 'mobx';

class AppStore{
    constructor(){
        makeAutoObservable(this)
    }
    todos=[// 初始化todos 
        { id:0, title: "todo标题",done: false,},
        { id:1, title: "已经完成 todo 的标题", done: true,}
    ]  
    addList(val){
        const id=this.todos.length
        this.todos.push({id,title:val,done:false})
        console.log(this.todos);
    }
    delList(){
        this.todos.pop()
    }
    clearList(){
        this.todos.length=0
    }
    changeFinished(id){
        // 改变 选中状态
        const list=this.todos.filter((item,index)=>item.id==id)// 通过id筛选
        list[0].done=!list[0].done// 取反
    }
    // 计算属性，重可观察属性 todos 衍生出来，返回没有完成的待办项的个数
    get unFinished(){
        console.log('computing...');
        const count=this.todos.filter((item) => item.done==false )
        return count.length
    }
}
export default new AppStore()